package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.VO.ClassVO;
import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.service.project.self.ISelfBuiltProjectService;
import com.blrs.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.SelfBuiltProject;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 自建项目Controller
 * 
 * @author yang
 * @date 2023-12-01
 */
@RestController
@RequestMapping("/self/project")
public class SelfBuiltProjectController extends BaseController
{
    @Autowired
    private ISelfBuiltProjectService selfBuiltProjectService;


    /**
     * 查询自建项目列表
     */
    //@PreAuthorize("@ss.hasPermi('self:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(SelfBuiltProject selfBuiltProject)
    {
        startPage();
        List<SelfBuiltProject> list = selfBuiltProjectService.selectSelfBuiltProjectList(selfBuiltProject);
        return getDataTable(list);
    }

    /**
     * 导出自建项目列表
     */
    //@PreAuthorize("@ss.hasPermi('self:project:export')")
    @Log(title = "自建项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SelfBuiltProject selfBuiltProject)
    {
        List<SelfBuiltProject> list = selfBuiltProjectService.selectSelfBuiltProjectList(selfBuiltProject);
        ExcelUtil<SelfBuiltProject> util = new ExcelUtil<SelfBuiltProject>(SelfBuiltProject.class);
        util.exportExcel(response, list, "自建项目数据");
    }

    /**
     * 获取自建项目详细信息
     */
    //@PreAuthorize("@ss.hasPermi('self:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") String projectId)
    {
        return success(selfBuiltProjectService.selectSelfBuiltProjectByProjectId(projectId));
    }

    /**
     * 新增自建项目
     */
    //@PreAuthorize("@ss.hasPermi('self:project:add')")
    @Log(title = "自建项目", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult add(@RequestBody SelfBuiltProject selfBuiltProject) throws NoSuchFieldException, IllegalAccessException {
        return toAjax(selfBuiltProjectService.insertSelfBuiltProject(selfBuiltProject));
    }

    /**
     * 修改自建项目
     */
    //@PreAuthorize("@ss.hasPermi('self:project:edit')")
    @Log(title = "自建项目", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult edit(@RequestBody SelfBuiltProject selfBuiltProject)
    {
        return toAjax(selfBuiltProjectService.updateSelfBuiltProject(selfBuiltProject));
    }

    /**
     * 删除自建项目
     */
    //@PreAuthorize("@ss.hasPermi('self:project:remove')")
    @Log(title = "自建项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable String[] projectIds)
    {
        return toAjax(selfBuiltProjectService.deleteSelfBuiltProjectByProjectIds(projectIds));
    }

    /**
     * 批量修改主分类
     */
    @PutMapping("/updateClass")
    public AjaxResult updateClass(@RequestBody ClassVO classVO) throws Exception
    {
        selfBuiltProjectService.updateClassIds(classVO.getEnterIds(),classVO.getClassId());
        return success("修改成功");
    }
}
